package world.ztomorrow.novel.listen;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import world.ztomorrow.common.dto.PageReqDto;
import world.ztomorrow.common.dto.PageRespDto;
import world.ztomorrow.common.dto.RestResp;
import world.ztomorrow.novel.dto.req.BookAddReqDto;
import world.ztomorrow.novel.dto.req.ChapterAddReqDto;
import world.ztomorrow.novel.dto.req.ChapterUpdateReqDto;
import world.ztomorrow.novel.dto.resp.BookChapterRespDto;
import world.ztomorrow.novel.dto.resp.BookInfoRespDto;
import world.ztomorrow.novel.dto.resp.ChapterContentRespDto;
import world.ztomorrow.novel.service.BookService;


@RestController
@RequiredArgsConstructor
public class AuthorListen {

    private final BookService bookService;

    /**
     * 小说发布接口
     */
    @PostMapping("/get_author/book")
    public RestResp<Void> publishBook(@RequestBody BookAddReqDto dto) {
        return bookService.saveBook(dto);
    }

    /**
     * 小说发布列表查询接口
     */
    @PostMapping("/get_author/books")
    public RestResp<PageRespDto<BookInfoRespDto>> listBooks(@RequestBody PageReqDto dto) {
        return bookService.listAuthorBooks(dto);
    }

    /**
     * 小说章节发布接口
     */
    @PostMapping("/book/chapter")
    public RestResp<Void> publishBookChapter(
            @RequestBody ChapterAddReqDto dto) {
        return bookService.saveBookChapter(dto);
    }

    /**
     * 小说章节删除接口
     */
    @DeleteMapping("/book/chapter/{chapterId}")
    public RestResp<Void> deleteBookChapter(@PathVariable("chapterId") Long chapterId) {
        return bookService.deleteBookChapter(chapterId);
    }

    /**
     * 小说章节查询接口
     */
    @GetMapping("/book/chapter/{chapterId}")
    public RestResp<ChapterContentRespDto> getBookChapter(@PathVariable("chapterId") Long chapterId) {
        return bookService.getBookChapter(chapterId);
    }

    /**
     * 小说章节更新接口
     */
    @PutMapping("/book/chapter/{chapterId}")
    public RestResp<Void> updateBookChapter(
            @PathVariable("chapterId") Long chapterId,
            @RequestBody ChapterUpdateReqDto dto) {
        return bookService.updateBookChapter(chapterId, dto);
    }

    /**
     * 小说章节发布列表查询接口
     */
    @PostMapping("/book/chapters/{bookId}")
    public RestResp<PageRespDto<BookChapterRespDto>> listBookChapters(
            @PathVariable("bookId") Long bookId,
            @RequestBody PageReqDto dto) {
        return bookService.listBookChapters(bookId, dto);
    }
}
